<extend name="Public/base"/>
<block name="body">
  <div class="main-title"><h2>{$data['id'] ? '编辑' : '新增'}商品</h2></div>
  <div class="tab-wrap">
    <ul class="tab-nav nav">
      <li class="current" data-tab="tab0"><a href="javascript:;">基本信息</a></li>
      <li data-tab="tab1"><a href="javascript:;">促销推荐</a></li>
    </ul>
  </div> 
  <form id="form" action="{:U('update')}" method="post" class="form-horizontal">
    <div class="item-field">
      <div class="tab-content">
        <div class="tab-pane in tab0">
          <!-- 基本信息开始 -->
          <h4 class="title"><i>1</i>商品基本信息</h4>
          
          <div class="form-item cf">
            <label class="item-label">商品分类</label>
            <div class="controls" id="J_itemCategory">加载中...</div>
            <input type="hidden" value="" name="category" id="J_category">
          </div>
          <neq name="IS_SUPPLIER" value="1">
          <if condition="$lists_supplier">
            <div class="form-item cf">
              <label class="item-label">供应商</label>
              <select name="supplier_id">
                <option value="0">自营</option>
                <volist name="lists_supplier" id="vo">
                  <option value="{$vo.supplier_id}">{:get_short($vo['name'],8)}</option>
                </volist>
              </select>
            </div>
          </if>
          <else/>
            <input type="hidden" name="supplier_id" value="{:session('user_auth')['uid']}" />
          </neq>
          <div class="form-item cf">
            <label class="item-label">商品编号<span class="check-tips">（系统自动生成编号，可自行修改）</span></label>
            <div class="controls">
              <input type="text" class="text input-mid" name="number" value="{$data['number'] ? $data['number'] : create_uniqid_sn(4)}">
            </div>
          </div>
          <div class="form-item cf">
            <label class="item-label">商品名称<span class="check-tips">（折扣优惠信息将高亮显示在商品名称后面）</span></label>
            <div class="controls">
              <input type="text" class="text input-large" name="name" value="{$data.name}">
              <input type="text" class="text input-mid" name="subname" value="{$data.subname}" placeholder="折扣优惠等，高亮显示">
            </div>
          </div>
            <!-- 商品标签 start  @author : wolfHua -->
            <label class="item-label">商品标签</label>
            <div class="form-item" id="sku_label" style="background: #fff;padding: 8px;border: 1px solid #ddd;">
                <if condition="$data.id gt 0">
                    <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 标签数据正在加载...</div>
                    <else/>
                    <div class="text-cancel">请先选择分类</div>
                </if>
            </div>
            <!-- 商品标签 end -->
          <div class="form-item cf">
            <label class="item-label">商品简介<span class="check-tips">（简介、折扣、优惠等信息，显示在商品名称下方）</span></label>
            <div class="controls">
              <textarea name="summary" class="textarea input-large" rows="4">{$data.summary}</textarea>
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">价格与库存<span class="check-tips">（默认市场价为本地价的1.5倍）</span></label>
            <div class="controls">
              <div class="field-group">
                <table>
                  <thead>
                    <tr>
                      <th>本店价</th>
                      <th>市场价</th>
                      <th>供应价</th>
                      <th>直播价</th>
                      <th>直播提成</th>
                      <th>库存</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td><input class="text input-small" name="price" id="price" type="number" value="{$data.price}"> (元)</td>
                      <td><input class="text input-small" name="mprice" id="mprice" type="number" value="{$data.mprice}"> (元)</td>
                      <td><input class="text input-small" name="gprice" id="gprice" type="number" value="{$data.gprice}"> (元)</td>
                      <td><input class="text input-small" name="zprice" id="zprice" type="number" value="{$data.zprice}"> (元)</td>
                      <td><input class="text input-small" name="ztrate" id="ztrate" type="number" value="{$data.ztrate}"> (元)</td>
                      <td><input class="text input-mini" name="stock" type="number" value="{$data.stock}"></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <!-- 重量 -->
          <div class="form-item">
            <label class="item-label">商品包装重量<span class="check-tips">（用于计算运费，务必统一单位为：<strong class="text-danger">千克kg</strong>）</span></label>
            <div class="controls">
              <input type="text" class="text input-small" name="weight" value="{$data.weight}"> <span class="text-danger">kg</span>
            </div>
          </div>
          
          <h4 class="title"><i>2</i>商品属性</h4>
          <div class="form-item" id="sku_prp">
            <if condition="$data.id gt 0">
              <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 属性数据正在加载...</div>
              <else/>
            <div class="text-cancel">请先选择分类</div>
            </if>
          </div>
          
          <h4 class="title"><i>3</i>商品规格</h4>
          
          <div class="form-item" style="background: #fff;padding:8px;margin-top: -6px;border: 1px solid #ddd" id="sku_spec">
            <if condition="$data.id gt 0">
              <div class="text-cancel"><img src="__IMG__/loading_icon.gif"/> 规格数据正在加载...</div>
              <else/>
            <div class="text-cancel">请先选择分类</div>
            </if>
          </div>
          <!-- 商品描述 -->
          <h4 class="title"><i>4</i>商品描述</h4>
          <div class="form-item">
            <label class="item-label">商品图片<span class="check-tips">（请上传大小为800px * 800px的商品图片，选中已上传的图片拖动鼠标可对图片进行排序，第一张为封面图片）</span></label>
            <div class="controls">
              {:hook('uploadImages', array('item_id' => $data['id'], 'name' => 'images', 'value' => $data['images'], 'thumb' => $data['thumb'], 'tpl' => 'thumb'))}
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">商品描述<span class="check-tips">（商品描述里插入的图片尺寸建议：宽度=800px，高度&lt;=1000px）</span></label>
            <div class="controls">
              <textarea name="intro">{$data.intro}</textarea>
              {:hook('adminArticleEdit', array('name' => 'intro','value' => $data['intro']))} </div>
          </div>
          <div class="form-item cf">
            <label class="item-label">是否上架<span class="check-tips">（未上架的商品将不会在前台显示）</span></label>
            <div class="controls">
              <label class="radio"><input type="radio" value="1" name="status">是</label>
              <label class="radio"><input type="radio" value="0" name="status">否</label>
            </div>
          </div>
          <div class="form-item" style="display:none;">
            <div class="controls">
              <label>
                <input type="checkbox" name="save_as_new_item" value="1">
                另存为新商品
              </label>
            </div>
          </div>
          <!-- 基本信息结束 -->
        </div>
        <div class="tab-pane tab1">
          <!--促销推荐开始-->
          
          <div class="form-item">
            <label class="item-label">推荐位置</label>
            <div class="controls">
              <label class="checkbox"><input type="checkbox" value="1" name="is_recommend">首页</label>
              <label class="checkbox"><input type="checkbox" value="1" name="is_new">新品</label>
              <label class="checkbox"><input type="checkbox" value="1" name="is_hot">热卖</label>
              <label class="checkbox"><input type="checkbox" value="1" name="is_promote">特价/抢购</label>
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">购买返积分<span class="check-tips">（积分数量，请设置为数字）</span></label>
            <div class="controls">
              <input type="text" class="text input-mini" name="credit" value="{$data.credit|default=0}" placeholder="默认不返积分">
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">商品排序<span class="check-tips">（请设置为数字，数字越小越靠前）</span></label>
            <div class="controls">
              <input type="text" class="text input-mini" name="sort" value="{$data.sort}">
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">是否置顶<span class="check-tips">（请设置为数字，0为不置顶，大于0则置顶，数字越大越靠前）</span></label>
            <div class="controls">
              <input type="text" class="text input-mini" name="is_top" value="{$data.is_top}">
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">购买数<span class="check-tips">（可手动设置商品购买数，真实购买数将在此基础上累加）</span></label>
            <div class="controls">
              <input type="text" class="text input-mini" name="buynum" value="{$data.buynum|default=0}">
            </div>
          </div>
          <div class="form-item">
            <label class="item-label">收藏数<span class="check-tips">（可手动设置商品收藏数量，真实收藏数将在此基础上累加）</span></label>
            <div class="controls">
              <input type="text" class="text input-mini" name="favnum" value="{$data.favnum|default=0}">
            </div>
          </div>
          <!-- 限购 -->
          <div class="form-item">
            <label class="item-label">用户限购设置<span class="check-tips">（不限购请设为 0 件）</span></label>
            <div class="controls">
              <select name="quota_hours">
                <option value="0">单订单</option>
                <option value="24">每天</option>
                <option value="168">每周</option>
                <option value="720">每月</option>
                <option value="8760">每年</option>
                <option value="87600">每用户</option>
              </select>
              限购 <input type="text" class="text input-mini text-center" name="quota_num" value="{$data.quota_num|default=0}"> 件
            </div>
          </div>
            <div class="form-item cf">
              <label class="item-label">分销返现类型<span class="check-tips">（按比例或者固定金额）</span></label>
              <div class="controls">
                <label class="radio"><input type="radio" value="0" name="sdp_type">固定金额</label>
                <label class="radio"><input type="radio" value="1" name="sdp_type">商品售价比例</label>
              </div>
            </div>
            <div class="form-item cf">
              <label class="item-label">分销返现<span class="J_sdp_label">比例</span><span class="check-tips">（请输入分销返现<span class="J_sdp_label">比例</span>）</span></label>
              <div class="controls">
                <input type="text" class="text input-mini" name="sdp" value="<php> if(is_null($data['sdp'])){ echo C('ALL');}else{ echo $data['sdp'];}</php>"> <span class="J_sdp_unit">%</span>
              
              </div>
            </div>   
          <if condition="C('DIS_START')">          
            <div class="form-item">
            <label class="item-label">推广返现比例
            <span class="check-tips">（以商品总价为基准,0则不返现，空则使用默认配置中的返现）</span>
            </label>
            <div class="controls">
           一级代理： <input type="text" class="text input-mini" name="sdp1" value='<php>if(is_null($data["sdp1"])){echo C("FIRISTNAME");}else{echo $data["sdp1"];}</php>'>%&nbsp&nbsp
            <if condition='C("DIS_CLASS") gt 1'>
            二级代理：<input type="text" class="text input-mini" name="sdp2" value='<php>if(is_null($data["sdp2"])){echo C("SECONDNAME");}else{echo $data["sdp2"];}</php>'>% &nbsp&nbsp
            </if>
            <if condition='C("DIS_CLASS") gt 2'>
            三级代理：<input type="text" class="text input-mini" name="sdp3" value='<php>if(is_null($data["sdp3"])){echo C("THIRDNAME");}else{echo $data["sdp3"];}</php>'>%
            </if>
            </div>
          </if>
          <if condition="$data">
            <div class="form-item">
              <label class="item-label">商品二维码
                <span class="check-tips">
                  （右键另存或直接 <a href="javascript:;" id="printQRcode">打印</a>）
                </span>
              </label>
              <dif class="controls qrcode">
                <div class="qrcode-area">
                  <if condition='$data.id gt 0'>
                  <!--img src="__ROOT__/{:C('QRCODE_CONFIG.rootPath')}Item/{$data.id}.png" id="qrcode" width="100" height="100" alt=""-->
                  </if>
                </div>
              </dif>
            </div>
          </if>
          <!--促销推荐结束-->
        </div>
      </div>
      <div class="form-item form-action cf">
        <button class="btn submit-btn ajax-post" id="submit" disabled type="submit" target-form="form-horizontal">保存</button>
        <a class="btn btn-return" href="{$Think.cookie.__forward__}">返 回</a>
        <input type="hidden" name="id" value="{$data.id|default=''}"/>
      </div>
    </div>
  </form>
</block>

<block name="script">
  <script src="__JS__/jquery/jquery.loadtype.js"></script>
  <script type="text/javascript" src="__JS__/jquery/jquery.printarea.js"></script> 
  <script type="text/javascript">
    $(function(){
      //导航高亮
      highlight_subnav("{:U('Item/index')}");
      // 导航切换
      showTab();
      //设置单选，复选，下拉菜单的值
      Core.setValue('quota_hours', '{$data.quota_hours|default = 0}');
      Core.setValue('is_recommend', '{$data.is_recommend|default = 0}');
      Core.setValue('is_new', '{$data.is_new|default = 0}');
      Core.setValue('is_hot', '{$data.is_hot|default = 0}');
      Core.setValue('is_promote', '{$data.is_promote|default = 0}');
      Core.setValue('status', '{$data.status|default = 0}');
      Core.setValue('sdp_type', '{$data.sdp_type|default = 0}');
      <neq name="IS_SUPPLIER" value="1">Core.setValue('supplier_id', '{$data.supplier_id|default = 0}');</neq>

      item.init();
      
      //商品分类
      $('#J_itemCategory').loadtype({
        type: 'itemCategory',
        name1: 'cid_1',
        name2: 'cid_2',
        name3: 'cid_3',
        value1: "{$data['cid_1']}",
        value2: "{$data['cid_2']}",
        value3: "{$data['cid_3']}",
        changed: function(c1, c2, c3){
          var c_array = [];
          c1 && c_array.push($('select[name="cid_1"] option:selected').text());
          c2 && c_array.push($('select[name="cid_2"] option:selected').text());
          c3 && c_array.push($('select[name="cid_3"] option:selected').text());
          $('#J_category').val(c_array.join('/'));
          var url = '{:U("Admin/ItemProperty/getProp?item_id=".$data["id"])}?cid_1=' + c1 + '&cid_2=' + c2 + '&cid_3=' + c3;
          var submit_checknumber = 0;
          $.get(url, function(data){
            if(data != null){
              $('#sku_prp').empty();
              $('#sku_prp').append(data);
            }else{
              $('#sku_prp').append('<div style="height:100px;line-height:100px;text-indent:20px;color:#f00;">您所选择的分类未绑定属性</div>');
            }
            submit_checknumber++;
            change_submit();
          });
          url = '{:U("Admin/ItemProperty/getProp?item_id=".$data["id"])}?type=specification&cid_1=' + c1 + '&cid_2=' + c2 + '&cid_3=' + c3;
          $.get(url, function(data){
            if(data != null){
              $('#sku_spec').empty();
              $('#sku_spec').append(data);
            }else{
              $('#sku_spec').append('<div style="height:100px;line-height:100px;text-indent:20px;color:#f00;">您所选择的分类未绑定规格</div>');
            }
            submit_checknumber++;
            change_submit();
          });
          var change_submit = function(){
            if(submit_checknumber === 2){
              $('#submit').removeAttr('disabled');
            }
          };

            //选择标签 author:wolfHua
            url = '{:U("Shop/ItemLabel/getLabel?item_id=".$data["id"])}?cid_1=' + c1 + '&cid_2=' + c2 ;
            $.get(url,function(data){
                if(data != null){
                    $('#sku_label').empty();
                    $('#sku_label').append(data);
                }
            });
        }
      });
    });
  </script>
</block>